/*
 * Created by JFormDesigner on Fri Aug 16 16:02:19 CST 2024
 */

package Teacher;

import Admin.Admin;
import bean.Course;
import bean.SelectCourse;

import java.awt.*;
import java.awt.event.*;
import java.util.List;
import javax.swing.*;

import static GetBound.getbound.getBound;
import static JDBCutil.JDBCUtil.getMyCourseList;
import static JDBCutil.JDBCUtil.getMyStudentList;

/**
 * @author 29454
 */
public class ForTeacher extends JFrame {
    private int teacherid;
    public ForTeacher(int teacherid) {
        this.teacherid = teacherid;
        initComponents();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(getBound());
        setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    private void ShowMyCourse(ActionEvent e) throws Exception {
        // TODO add your code here
        List<Course> list=getMyCourseList(teacherid);
        ShowMyCourse myCourse=new ShowMyCourse(list);
        myCourse.setVisible(true);
        scrollPane1.setViewportView(myCourse);
    }

    private void Score(ActionEvent e) throws Exception {
        // TODO add your code here
        int[] ids = Admin.getSelectedid(ShowMyCourse.getTable1());
        if(ids.length>1){
            JOptionPane.showMessageDialog(this, "只能选择一个课程！");
        }
        else{
            int courseid=ids[0];
            List<SelectCourse> list=getMyStudentList(courseid,teacherid);
            ShowMyStudent myStudent=new ShowMyStudent(list);
            myStudent.setVisible(true);
            scrollPane1.setViewportView(myStudent);
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        button1 = new JButton();
        button2 = new JButton();
        scrollPane1 = new JScrollPane();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("\u6211\u7684\u8bfe\u7a0b");
        button1.addActionListener(e -> {try {
ShowMyCourse(e);} catch (Exception ex) {
    throw new RuntimeException(ex);
}});
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(5, 5), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u6210\u7ee9\u7ba1\u7406");
        button2.addActionListener(e -> {try {
Score(e);} catch (Exception ex) {
    throw new RuntimeException(ex);
}});
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(88, 5), button2.getPreferredSize()));
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(10, 65, 1700, 850);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JButton button1;
    private JButton button2;
    private JScrollPane scrollPane1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
